layui.use(['laydate','form','table','layer','laytpl'], function(){
	var laydate = layui.laydate,form = layui.form,table = layui.table,layer = layui.layer,laytpl = layui.laytpl;
	/*开始时间*/
	laydate.render({
	  	elem: '#start' //指定元素
	});
	/*结束时间*/
	laydate.render({
	  	elem: '#end' //指定元素
	});
	/*@条件*/
	var ids = $('input[name="ids"]').val()
	var type = $('input[name="type"]').val()
	var where = {ids: ids, type: type};
	/*@初始化table*/
	var tableObj = table.render({
	    elem: '#table-list',
	    url: '/staff/repair/index', //数据接口
	    page: false, //开启分页
	    where: where,
	    limits: false,
	    cols: [[ //表头
	    	{field: 'repair_id', title: '序号'},
	    	{field: 'shopname', title: '维修门店'},
	    	{field: 'repair_sn', title: '维修编号'},
	    	{field: 'addtime', title: '订单时间'},
	    	{field: 'username', title: '客户姓名'},
	    	{field: 'phone', title: '联系方式'},
	    	{field: 'user_sn', title: '客户编号'},
	    	{field: 'goods_name', title: '设备名称'},
	    	{field: 'imei', title: 'IMEI'},
	    	{field: 'sn', title: 'S/N'},
	    	{field: 'repair_money', title: '维修金额'},
	    	{field: 'parts_money', title: '配件金额'},
	    	{field: 'people_money', title: '人工费金额'},
	    	{field: 'ratio_money', title: '维修提成'},
	    	{field: 'admin_nkname', title: '工作人员'},
	    	{field: 'tech_nkname', title: '维修人员'},
	    	{title: '操作', width: '100', toolbar: '<div><a class="layui-btn" onclick="xadmin.open(\'维修详情\',\'/staff/repair/details/ids/{{d.repair_id}}\')">详情</a></div>'}
	    ]],
	    parseData: function(res){
	    	var all = res.data.count
	    	res.data = res.data.list
	    	/*@统计*/
			var getTpl_2 = order_count.innerHTML;
			var count = document.getElementById('order-count');
			laytpl(getTpl_2).render(all, function(html){
				count.innerHTML = html;
			});
	    },
	});
	/*@查询*/
	form.on('submit(search)',function(data){

		if(data.field.start != '' && data.field.end != ''){
			var startDate = new Date(data.field.start).getTime();
			var endDate = new Date(data.field.end).getTime();
			if(startDate > endDate){
				layer.msg('开始时间不能大于结束时间',{icon: 2})
				return false
			}
		}
		/*重载表格数据*/
		tableObj.reload({
			page: {
                page: 1 //重新从第 1 页开始
            },
            where: data.field
        });
        return false
	})
});